# a = {} # 创建一个空字典
# b = dict() # 使用函数创建字典
# print(type(a))
# print(type(b))

# student = {'id': 1,'name': 'zhangsan'} # 创建字典并初始化
# print(student) # 打印字典数据

# student = {
#     'id': 1,
#     'name': 'zhangsan',
# } # 创建字典并分行初始化
# print(student) # 打印字典数据

# student = {
#     'id': 1,
#     'name': 'zhangsan',
# }
# print('id' in student)    # 判断key值id是否存在
# print('score' in student) # 判断key值score是否存在

# student = {
#     'id': 1,
#     'name': 'zhangsan',
# }
# print(student['id'])   # key值id对应的值
# print(student['name']) # key值name对应的值

# student = {
#     'id': 1,
#     'name': 'zhangsan',
# }
# print(student['score'])   # key值score对应的值，不存在则抛异常

# student = {
#     'id': 1,
#     'name': 'zhangsan'
# }
#
# print(student)
# student['score'] = 90 #key值score不存在则新增键值对
# print(student)

# student = {
#     'id': 1,
#     'name': 'zhangsan',
#     'score': 80
# }
#
# print(student)
# student['score'] = 90 # key值已经存在，即对键值对值进行修改
# print(student)

# student = {
#     'id': 1,
#     'name': 'zhangsan',
#     'score': 80
# }
#
# print(student)
# student.pop('score') # 删除key值为score的键值对
# print(student)

# student = {
#     'id': 1,
#     'name': 'zhangsan',
#     'score': 80
# }
#
# for key in student:
#     print(key,student[key])

# student = {
#     'id': 1,
#     'name': 'zhangsan',
#     'score': 80
# }
#
# print(student.keys()) # 使用keys获取所有key值

# student = {
#     'id': 1,
#     'name': 'zhangsan',
#     'score': 80
# }
#
# print(student.values()) # 使用values获取所有value值

# student = {
#     'id': 1,
#     'name': 'zhangsan',
#     'score': 80
# }
#
# print(student.items()) # 使用items获取所有键值对

# print(hash(0)) # 计算hash值
# print(hash(3.14))
# print(hash('hello'))
# print(hash(True))
# print(hash(()))

# print(hash([1,2,3])) # 列表不能计算hash值

# print(hash({'id': 1})) # 字典不能计算hash值

# f = open('d:/test.txt', 'r')  # 以读的方式打开文件

# flist = []
# count = 0
# while True:
#     f = open('d:/test.txt', 'r') # 需要现在d盘路径下创建一个test.txt文件
#     flist.append(f) # 尾插文件对象
#     count += 1
#     print(f'count = {count}')

# f = open('d:/test.txt', 'w')  # 以写的方式打开文件
# f.write('hello')  # 向文件中写入hello字符串
# f.close()  # 关闭文件

# f = open('d:/test.txt', 'r')  # 以读的方式打开文件
# f.write('hello')  # 向文件中写入hello字符串
# f.close()  # 关闭文件

# f = open('d:/test.txt', 'w')  # 以写的方式打开文件
# f.write('hello')  # 向文件中写入hello字符串
# f.close()   # 关闭文件
#
# f = open('d:/test.txt', 'a')  # 以追加的方式打开文件
# f.write(' world')   # 向文件中追加写入 world
# f.close()  # 关闭文件

# f = open('d:/test.txt', 'w')
# f.write('hello')  # 向文件写入hello字符串
# f.close()  # 关闭文件
# f.write('world')  # 文件关闭之后写入文件内容抛异常

# f = open('d:/test.txt', 'r')  # 以读的方式打开文件
# result = f.read(2)  # 读取两个字符
# print(result)
# f.close()   # 关闭文件

# f = open('d:/test.txt', 'r')
# for line in f:
#     print(f'line = {line}')  # 以行读取文件
# f.close()

# f = open('d:/test.txt', 'r')
# for line in f:
#     print(f'line = {line}', end='')  # 以行读取文件，并手动去掉换行
# f.close()

f = open('d:/test.txt', 'r')
lines = f.readlines()  # 读取整个文件内容
print(lines)
f.close()
